package com.husd.leetcode.math;

/**
 * @author hushengdong
 */
public class FastSqrt {

    //快速平方根倒数
    public static double fastInverseSqrt(double x) {

        double halfX = 0.5 * x;
        int i = (int) x;
        i = 0x5f3759df - (i >> 1);
        x = i;
        x = x * (1.5 - (halfX * x * x));
        return x;
    }

    public static void main(String[] args) {

        System.out.println(fastInverseSqrt(4.0));
    }
}
